package dev.hxliu.cn;

import dev.hxliu.cn.util.DataMaskingUtils;
import dev.hxliu.cn.util.InjectValueUtil;
import dev.hxliu.cn.vo.MerchantUserPageVO;
import lombok.experimental.ExtensionMethod;

import java.time.LocalDateTime;

/**
 * Hello world!
 *
 */
@ExtensionMethod({InjectValueUtil.class})
public class Test
{
    // TODO 启动时需要加上--add-opens java.base/java.lang=ALL-UNNAMED
    public static void main(String[] args)  {
        MerchantUserPageVO merchantUserPageVO = new MerchantUserPageVO();
        merchantUserPageVO.setPhone("12345678901");
        System.out.println(merchantUserPageVO.injectObject1());
        merchantUserPageVO.setPhone("12345678901");
        System.out.println(merchantUserPageVO.injectObject());
        merchantUserPageVO.setPhone("12345678901");
        System.out.println(merchantUserPageVO.inject());
        // methodHandles
        {
            long start = System.currentTimeMillis();
            for (int i = 0; i < 30000000; i++) {
                merchantUserPageVO.injectObject();
            }
            long end = System.currentTimeMillis();
            System.out.println("方法句柄设置值"+(end - start));
        }

        // methodHandles + 指定类名称
        {
            long start = System.currentTimeMillis();
            for (int i = 0; i < 30000000; i++) {
                merchantUserPageVO.injectObject(MerchantUserPageVO.class);
            }
            long end = System.currentTimeMillis();
            System.out.println("方法句柄设置值指定类"+(end - start));
        }
        // javassist 类
        {
            long start = System.currentTimeMillis();
            for (int i = 0; i < 30000000; i++) {
                merchantUserPageVO.injectObject1();
            }
            long end = System.currentTimeMillis();
            System.out.println("javassist类"+(end - start));
        }
        // javassist 类 (少了根据类拿Class的操作）
        {
            long start = System.currentTimeMillis();
            for (int i = 0; i < 30000000; i++) {
                merchantUserPageVO.injectObject1(MerchantUserPageVO.class);
            }
            long end = System.currentTimeMillis();
            System.out.println("javassist类指定类"+(end - start));
        }
        {
            long start = System.currentTimeMillis();
            for (int i = 0; i < 30000000; i++) {
                merchantUserPageVO.inject();
            }
            long end = System.currentTimeMillis();
            System.out.println("手写inject方法实现"+(end - start));
        }

        {
            long start = System.currentTimeMillis();
            for (int i = 0; i < 30000000; i++) {
                merchantUserPageVO.setCreateTime(LocalDateTime.now());
                merchantUserPageVO.setPhone(DataMaskingUtils.phoneMasking(merchantUserPageVO.getPhone()));
            }
            long end = System.currentTimeMillis();
            System.out.println("手写逻辑代码"+(end - start));
        }
    }
}
